let compare a b =
    match a with
        a when a=b -> 0
        | a when a>b -> 1
        | _ -> -1;; 

let rec  find nom liste =
    match liste with
        [] -> invalid_arg "Le compte n'existe pas"
        | e::l -> let (e1,e2) = e in let le1 = String.lowercase e1 in
            match le1 with
                le1 when le1 = String.lowercase nom -> e2 
               |_ -> find (String.lowercase nom) l;;
find "Toto" [("Don", 435.);("Nut",75.);("Toto",42.)];;
let l42 =  [("Don", 435.);("Nut",75.);("Toto",42.)];;

lowercase;;

let rec add (nom,num) liste =
    match liste with 
        [] -> [(nom, num)]
        | (e1,e2)::l -> let tri = compare (String.lowercase nom) (String.lowercase e1) in 
            match tri with
                 1 -> (e1,e2) :: add (nom,num) l           
                |0 -> liste
                |_ -> (nom,num)::liste ;;

add ("ToTO", 4352.) l42;;

let rec delete nom liste =
    match liste with 
        [] -> []
        | (e1,e2)::l -> let tri = compare nom e1 in 
            match tri with
                 1 -> (e1,e2) :: delete nom l           
                |0 -> l
                |_ -> liste ;;
delete "Nut" l42;;

let rec update nom num liste =
    match liste with 
        [] -> []
        | (e1,e2)::l -> let tri = compare nom e1 in 
            match tri with
                 1 -> (e1,e2) :: update nom num l           
                |0 -> (e1, num)::l
                |_ -> liste ;; 

update "Toto" 45. l42;;

let rec name nom nouvnom liste =
    match liste with 
        [] -> []
        | (e1,e2)::l -> let tri = compare nom e1 in 
            match tri with
                 1 -> (e1,e2) :: name nom nouvnom l           
                |0 -> (nouvnom, e2)::l
                |_ -> liste ;; 

update "Toto" 45. l42;;

let rec sales liste reduc =
    match liste with
        [] -> []
        |(e1,e2)::l -> (e1, (e2 -. e2*.reduc/. 100.)):: sales l reduc;;    

sales l42 10.;;
